package com.suixun;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.suixun.enums.APICode;

import org.springframework.stereotype.Component;
import org.springframework.ui.Model;

/**
 * 返回消息，由spring组装成json
 * {"code":0,"msg":"XXXX","data":{}}
 *
 * @author <a href="mailto:hellmash@gmail.com">hellmash</a>
 * @version create on 2015-04-24 09:48
 */
@Component
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result extends ResourceBean{

    private Result(){}
    public Result(APICode _code, Object _data){
        this.msg = _code.getMsg();
        this.code = Integer.toString(_code.getCode());
        this.data = _data;
    }

    /**
     * 结果编号
     */
    public String code = "200";

    /**
     * 返回消息
     */
    public String msg;
    public Object data;
    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @JsonProperty("data")
    public Object getData() {
        return data;
    }

    public void setData(Model data) {
        this.data = data;
    }

    @Override
    public String toKey() {
        return this.code;
    }
}
